#ifndef COMPILER_MANAGER_H
#define COMPILER_MANAGER_H

#include <QObject>
#include <QProcess>
#include <QMap>

class CompilerManager : public QObject {
    Q_OBJECT
    
public:
    enum Language {
        C,
        CPP,
        JavaScript,
        TypeScript,
        Python
    };
    
    explicit CompilerManager(QObject *parent = nullptr);
    ~CompilerManager();
    
    bool compile(const QString &sourceFile, Language language, const QString &outputFile = "");
    bool hasCompiler(Language language) const;
    
signals:
    void compilationStarted();
    void compilationFinished(bool success, const QString &output);
    
private slots:
    void onProcessFinished(int exitCode, QProcess::ExitStatus exitStatus);
    void onReadyReadStandardOutput();
    void onReadyReadStandardError();
    
private:
    struct CompilerInfo {
        QString compilerPath;
        QStringList defaultArgs;
    };
    
    QMap<Language, CompilerInfo> compilers;
    QProcess *currentProcess;
    QString outputBuffer;
    
    void detectCompilers();
    QString getCompilerName(Language language) const;
};

#endif // COMPILER_MANAGER_H